package com.hand.wfive.view.countdowntime;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;

import com.hand.wfive.R;

public class CountDownTimerView extends BaseCountDownTimerView {

    private int timeBackgroundColor;
    private int timeStrokeColor;
    private int timeStrokePadingV;
    private int timeStrokePadingH;
    private int timeTextColor;
    private int timeSeparatorColor;
    private int timeSeparatorType;
    private float timeTextSize;
    private float timeSeparatorTextSize;
    private int timeSeparatorPaddingHor;
    private int timeBackgroundRadius;
    private boolean timetextisbold = false;

    public CountDownTimerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DownTimerView);
        timeBackgroundColor = ta.getColor(R.styleable.DownTimerView_timeBackgroundColor, Color.parseColor("#00ffffff"));
        timeStrokeColor = ta.getColor(R.styleable.DownTimerView_timeStrokeColor, Color.parseColor("#ffffff"));
        timeTextColor = ta.getColor(R.styleable.DownTimerView_timeTextColor, Color.parseColor("#ffffff"));
        timeSeparatorColor = ta.getColor(R.styleable.DownTimerView_timeSeparatorColor, Color.parseColor("#00ffffff"));
        timeSeparatorType = ta.getInt(R.styleable.DownTimerView_timeSeparatorType, TYPE_LABEL_COLON);
        timeBackgroundRadius = ta.getInt(R.styleable.DownTimerView_timeBackgroundRadius, 0);
        timeTextSize = ta.getDimension(R.styleable.DownTimerView_timeTextSize, 12);
        timeSeparatorTextSize = ta.getDimension(R.styleable.DownTimerView_timeSeparatorSize, 12);
        timeSeparatorPaddingHor = ta.getInt(R.styleable.DownTimerView_timeSeparatorPaddingHor, dp2px(0));
        timeStrokePadingV = ta.getInt(R.styleable.DownTimerView_timeStrokePadingV, dp2px(0));
        timeStrokePadingH = ta.getInt(R.styleable.DownTimerView_timeStrokePadingH, dp2px(0));
        timetextisbold = ta.getBoolean(R.styleable.DownTimerView_timetextisbold, false);
        init();
    }

    public CountDownTimerView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CountDownTimerView(Context context) {
        this(context, null);
    }

    @Override
    protected int getStrokeColor() {
        return timeStrokeColor;
    }

    @Override
    protected int getStrokepadingV() {
        return timeStrokePadingV;
    }

    @Override
    protected int getStrokepadingH() {
        return timeStrokePadingH;
    }

    @Override
    protected int getLabelTextColor() {
        return timeTextColor; //这个属性有个问题 设置#ffffff无效，其它任意色值如fffffe可以，没找到原因
    }

    @Override
    protected int getSeparatorTextColor() {
        return timeSeparatorColor;
    }

    @Override
    protected int getSeparatorPaddingHor() {
        return dp2px(timeSeparatorPaddingHor);
    }

    @Override
    protected int getCornerRadius() {
        return timeBackgroundRadius;
    }

    /**
     * 获取是否加粗
     *
     * @return
     */
    @Override
    protected boolean getTimetextisbold() {
        return timetextisbold;
    }

    @Override
    protected int getLabelType() {
        return timeSeparatorType;
    }

    @Override
    protected float getTextSize() {
        return timeTextSize;
    }


    @Override
    protected float getSeparatorTextSize() {
        return timeSeparatorTextSize;
    }

    @Override
    protected int getBackgroundColor() {
        return timeBackgroundColor;
    }


    protected int dp2px(float dp) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }

    protected int sp2px(float sp) {
        final float scale = getContext().getResources().getDisplayMetrics().scaledDensity;
        return (int) (sp * scale + 0.5f);
    }

}
